<?php

class Images {

    private $_images = array();

    public function getImages() {
        return $this->_images;
    }

    public function setImages($images) {
        $this->_images = $images;
        return $this;
    }

    public function addImage($image){
        array_push($this->_images, $image);
    }
    
    function __construct(array $donnees) {
        $this->hydrate($donnees);
    }

    public function __toString() {
        return print_r($this->_images, true);
    }

    public function hydrate(array $donnees) {
        foreach ($donnees as $key => $value) {
            // On récupère le nom du setter correspondant à l'attribut.
            $method = 'set' . ucfirst($key);

            // Si le setter correspondant existe.
            if (method_exists($this, $method)) {
                // On appelle le setter.
                $this->$method($value);
            }
        }
    }

}

?>
